package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {


    /**
     * @description: 插入菜品数据
     * @author: zhouzhijie
     * @date: 2023/11/13 17:06
     * @param: [dish]
     * @return: 
     **/
    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);

    /**
     * @description: 菜品分页查询
     * @author: zhouzhijie
     * @date: 2023/11/15 14:00
     * @param: [dishPageQueryDTO]
     * @return:
     **/
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    /**
     * @description: 根据主键查询菜品
     * @author: zhouzhijie
     * @date: 2023/11/15 14:49
     * @param: [id]
     * @return:
     **/
    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    /**
     * @description: 根据id批量删除菜品
     * @author: zhouzhijie
     * @date: 2023/11/15 15:35
     * @param: [dishids]
     * @return:
     **/
    void deleteBatchByIds(List<Long> ids);


    /**
     * @description: 根据id动态修改菜品
     * @author: zhouzhijie
     * @date: 2023/11/16 18:06
     * @param: [dish]
     * @return:
     **/
    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * @description: 根据分类id查找菜品
     * @author: zhouzhijie
     * @date: 2023/11/17 9:08
     * @param: [categoryId]
     * @return: 
     **/
    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> getDishesByCategoryId(Long categoryId);

    /**
     * @description: 动态条件查询菜品
     * @author: zhouzhijie
     * @date: 2023/11/17 9:54
     * @param: [dish]
     * @return:
     **/
    List<Dish> list(Dish dish);

    /**
     * @description: 根据套餐id获取菜品信息
     * @author: zhouzhijie
     * @date: 2023/11/18 17:59
     * @param: [id]
     * @return:
     **/
    @Select("select d.* from dish d left join setmeal_dish s on d.id = s.dish_id where setmeal_id = #{setmealId}")
    List<Dish> getBySetmealId(Long setmealId);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
